package me.spring.cloud.common.components.oauth2.basic.utils;

import me.spring.cloud.common.components.oauth2.basic.BasicUserInfo;
import me.spring.cloud.common.components.oauth2.userdetails.exception.AuthUserException;
import me.spring.cloud.common.components.oauth2.userdetails.exception.code.AuthoritiesCode;
import me.spring.cloud.common.components.oauth2.userdetails.util.UserInfoUtil;

/**
 * @author luffy
 */
public class SecurityUtils {

  public static BasicUserInfo getUserInfo() {
    BasicUserInfo user = UserInfoUtil.getUserInfo(BasicUserInfo.class);
    if (user != null) {
      return user;
    }
    throw new AuthUserException(AuthoritiesCode.CLIENT_VALID_TOKEN_ERROR);
  }

  public static String getUsername() {
    return getUserInfo().getUsername();
  }

  public static String getUserId() {
    return getUserInfo().getId();
  }

}
